package com.kgc.mall.service.impl;


import com.kgc.mall.mapper.UserMapper;
import com.kgc.mall.pojo.User;
import com.kgc.mall.service.UserService;
import com.kgc.mall.util.MyBatisUtil;


import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {
    private  static UserMapper userMapper= MyBatisUtil.getMapper(UserMapper.class);

    @Override

    public List<User> getUserInfoByPage(String loginName, String userName, int pageNum, int pageSize) {
        UserMapper userMapper= MyBatisUtil.getMapper(UserMapper.class);
        List<User> userList=new ArrayList<>();
        int starNO=(pageNum-1)*pageSize;
        userList =  userMapper.getUsersByPaging(starNO,pageSize,loginName,userName);
        return userList;

    }

    @Override
    public int addUserInfo(User user) {
        return  userMapper.insertUser(user);
    }

    @Override
    public int updateUserInfo(User user) {
        return  userMapper.updateUser(user);
    }

    @Override
    public User getUserInfo(int userId) {
        return userMapper.getUser(userId);
    }

    @Override
    public int deleteUserByUid(int userId) {
        return userMapper.delectUser(userId);
    }

    @Override
    public long getUserTotalCount(String loginName, String userName) {
        UserMapper userMapper=MyBatisUtil.getMapper(UserMapper.class);

        long count=userMapper.getUserTotalCount(loginName,userName);
        return count;
    }
}
